//
// Created by x on 2/4/24.
//

#ifndef BOOST_ASIO_MTCPSERVER_H
#define BOOST_ASIO_MTCPSERVER_H

#include <asio.hpp>
#include <memory>
#include <list>
#include "msockettcp.h"
using namespace asio;
using namespace asio::ip;
using std::list;
using std::shared_ptr;
class MTCPServer {
public:
    MTCPServer(short port = 12345);
    void run();
    void startAccept();
    void printf_pool(asio::thread_pool& pool);
    static void handleClient(tcp::socket* socket,const asio::error_code& error);
    static void write(tcp::socket* socket,std::string str);
    ~MTCPServer();
private:
    io_context io_context_;
    short port;
    ip::tcp::acceptor acceptor_;
    shared_ptr<MSocketTCP> socket_;
    list<shared_ptr<MSocketTCP>> clients_; // <socket>
    shared_ptr<asio::thread_pool> thread_pool_;
};


#endif //BOOST_ASIO_MTCPSERVER_H
